[[alloc] init] as a factory method
Posted
by iter
on Stack Overflow
See other posts from Stack Overflow
or by iter
Published on 2010-05-19T05:51:03Z
Indexed on
2010/05/19
6:00 UTC
Read the original article
Hit count: 168
objective-c
|oop
I want to initialize an instance of one of the subclasses of a superclass depending on the arguments to init:
[[Vehicle alloc] initWithItinerary: shortWay]; // returns a bicycle
[[Vehicle alloc] initWithItinerary: longWay]; // returns a car
I can't find examples of code like this. I wonder if this is not idiomatic in Objective C, or I simply am not looking in the right places.
© Stack Overflow or respective owner